package com.lcz.googleplay.holder;

import android.view.View;
import android.widget.RelativeLayout;

import com.lcz.googleplay.R;
import com.lcz.googleplay.adapter.DefaultAdapter;
import com.lcz.googleplay.utils.UIUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hp on 2016/10/29.
 */

public class MoreHolder extends BaseHolder<Integer> {
    public static final int HAS_NO_MORE = 0;  // 没有额外数据了
    public static final int LOAD_ERROR = 1;// 加载失败
    public static final int HAS_MORE = 2;//  有额外数据

    @BindView(R.id.rl_more_loading)
    RelativeLayout rlMoreLoading;
    @BindView(R.id.rl_more_error)
    RelativeLayout rlMoreError;

    public MoreHolder(DefaultAdapter adapter) {
        this.adapter = adapter;
    }

    @Override
    public View init() {
        View view = View.inflate(UIUtils.getActivity(), R.layout.item_more, null);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void refreshView(Integer data) {
        rlMoreLoading.setVisibility(data == HAS_MORE ? View.VISIBLE : View.GONE);
        rlMoreError.setVisibility(data == LOAD_ERROR ? View.VISIBLE : View.GONE);
    }

    @Override
    public View getView() {
        //得到最后一个条目
        loadMore();
        return super.getView();
    }


    private DefaultAdapter adapter;

    /*每个界面加载内容不同，所以交给adapter加载*/
    private void loadMore() {
        adapter.loadMore();
    }
}
